package com.zhangyu.eat.register.modle;

import android.content.Intent;
import android.graphics.Path;
import android.os.SystemClock;
import android.text.method.BaseKeyListener;
import android.util.Log;
import android.widget.Toast;

import com.avos.avoscloud.AVException;
import com.avos.avoscloud.AVUser;
import com.avos.avoscloud.SignUpCallback;
import com.zhangyu.eat.base.bean.Myuser;
import com.zhangyu.eat.main.view.MainActivity;
import com.zhangyu.eat.register.view.RegisterActivity;

/**
 * Created by SoSho on 2016/10/15.
 */

public class RegisterBiz implements UserRegisterBiz {

    @Override
    public void Register(final String name, final String nikeName, final String password, final String imagePath, final RegisterListenter listener) {
        AVUser avUser=new AVUser();
//        AVUser.getCurrentUser().put("image",imagePath);
//        AVUser.getCurrentUser().put("nike",nikeName);
//        avUser.setUsername(name);
        avUser.setPassword(password);
        Myuser user = new Myuser();
        user.setNickName(nikeName);
        user.setImagePath(imagePath);
        Log.d("RegisterBiz", imagePath);
        user.setUsername(name);// 设置用户名
        user.setPassword(password);// 设置密码
        Log.d("RegisterBiz", password);

        user.signUpInBackground(new SignUpCallback() {
            @Override
            public void done(AVException e) {
                if (e == null) {
                    // 注册成功，把用户对象赋值给当前用户 AVUser.getCurrentUser()
                    listener.registerSucceed();

                } else {
                    // 失败的原因可能有多种，常见的是用户名已经存在。
                    Log.d("RegisterBiz", e.getMessage());
                    listener.registerFailed();
                }
            }
        });
    }


}
